<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>document选择器</title>
  </head>
  <body>
    <button id="btn">测试</button>
    <button class="btn1">测试</button>
    <button b="2">测试</button>
    <button>测试</button>
    <button>测试</button>
    <script>
      // document.querySelector('button').onclick = () =>{
      // alert('测试')
      // }
      // document.querySelectorAll('button').forEach(item =>{
      // item.onclick=()=>{
      // alert('测试')
      // }
      // })
      document.querySelector("#btn").onclick = () => {
        alert("测试");
      };
      document.querySelector(".btn1").onclick = () => {
        alert("测试");
      };
      document.querySelector("button[b='2']").onclick=()=>{
        alert("测试111");
      }
    </script>
  </body>
</html>
